<!DOCTYPE html>
<html>
<head>
<title>SoundJS: Preload & Sound APIs</title>

	<script type="text/javascript" src="./assets/preloadjs-0.2.0.min.js"></script>

	<script type="text/javascript" src="../src/soundjs/SoundJS.js"></script>
	<script type="text/javascript" src="../src/soundjs/HTMLAudioPlugin.js"></script>
	<script type="text/javascript" src="../src/swfobject.js"></script>
	<script type="text/javascript" src="../src/soundjs/FlashPlugin.js"></script>

	<!-- We also provide hosted minified versions of all CreateJS libraries.
	    http://code.createjs.com -->

	<script>
	var queue;
	var displayStatus;

	function init() {
		if (window.top != window) {
			document.getElementById("header").style.display = "none";
		}
		
		createjs.FlashPlugin.BASE_PATH = "../src/soundjs/" // Initialize the base path from this document to the Flash Plugin
		if (!createjs.SoundJS.checkPlugin(true)) {
			document.getElementById("error").style.display = "block";
			document.getElementById("content").style.display = "none";
			return;
		}

		displayStatus = document.getElementById("status");

		// Create a single item to load.
		var assetsPath = "assets/";
		var item = {src:assetsPath+"18-machinae_supremacy-lord_krutors_dominion.mp3|"+assetsPath+"18-machinae_supremacy-lord_krutors_dominion.ogg", id:"music"};

		// Instantiate a queue.
		queue = new createjs.PreloadJS();
		queue.installPlugin(createjs.SoundJS); // Plug in SoundJS to handle browser-specific paths
		queue.onComplete = loadComplete;
		queue.onFileError = handleFileError;
		queue.onProgress = handleProgress;
		queue.loadFile(item, true);
	}

	function stop() {
		if (queue != null) { queue.cancel(); }
		createjs.SoundJS.stop();
	}

	function handleFileError(o) {
		// An error occurred.
		displayStatus.innerText = "Error :("
	}

	function handleProgress(event) {
		// Progress happened.
		displayStatus.innerText = "Loading: " + (queue.progress.toFixed(2) * 100) + "%";
	}

	function loadComplete() {
		// Load completed.
		displayStatus.innerText = "Complete :)";
		playSound("music");
	}

	function playSound(name, loop) {
		// Play the sound using the ID created above.
		return createjs.SoundJS.play(name);
	}
	</script>

	<link rel="stylesheet" type="text/css" href="assets/demoStyles.css" />
</head>

<body onload="init()">

	<header id="header" class="SoundJS">
	    <h1><span class="text-product">Sound<strong>JS</strong></span> Preload And Play</h1>
	    <p>This example preloads an audio instance, and immediately plays it using SoundJS. A different audio source will be chosen by SoundJS depending on the browser capabilities. Note that this will not work without a web server in some browsers.</p>
	</header>

	<div class="content" id="content">
		<h1 id="status">Loading...</h1>
	</div>
	
	<div id="error">
		<h1>Sorry!</h1>
		<p>SoundJS is not currently supported in your browser.</p>
		<p>We are currently working on support for iOS. Please <a href="http://github.com/CreateJS/SoundJS/issues" target="_blank">log a bug</a>
			if you see this in any other browsers.</p>
	</div>

</body>
</html>
